package com.tcs.validation;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tcs.model.porxypool.proxyPoolBean;
import com.tcs.util.constant.SystemConstants;
import com.tcs.util.staticpack.StaticPack;
import com.tcs.validation.task.TimingValidationTask;

/**
* @Title: TimingValidation.java
* @Package com.tcs.validation
* @author 神经刀
* @date 2018年8月11日
* @version V1.0
 */
@Service(value="iimingValidation")
public class TimingValidation implements ITimingValidation {
	
	// 这里不使用 quartz 的定时任务.
	private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(SystemConstants.ProxyPool.SINGLENUM);
	
	@Resource(name="staticPack")
	private StaticPack<String,proxyPoolBean> staticPack;
	
	@Override
	public void validation() {
		proxyPoolBean proxyPoolBean = staticPack.get(SystemConstants.ProxyPool.PROXYPOOLMODEL);
		scheduler.scheduleAtFixedRate((Runnable)new TimingValidationTask(), 0, proxyPoolBean.getValidationConfig().getTime(), TimeUnit.MINUTES);
	}

}